package com.wan.net.handler.client;

import com.wan.net.core.packet.Packet;
import com.wan.net.handler.protobuf.Processor;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

public class ProtobufClientChannelHandler extends AbstractClientChannelHandler {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Packet packet) throws Exception {
        Processor handler = Processor.getClientProcessor(packet.getMessageId());
        if(handler == null){
            logger.error("[client]找不到协议号[{}]对应的处理器",packet.getMessageId());
            return;
        }
        Channel channel = channelHandlerContext.channel();
        try {
            handler.process(channel, packet);
        }catch (Exception e){
            logger.error("[client]协议[{}]处理异常",packet.getMessageId(),e);
        }
    }
}
